#ifndef CNETWORKMANAGER_H_INCLUDED
#define CNETWORKMANAGER_H_INCLUDED

#include "LON.h"

class CGameManager;

enum RAKNET_MESSAGE_ID {
  //! For Chat
  ID_LON_CHAT = ID_USER_PACKET_ENUM,

  //! For CStateLogin
  ID_LON_LOGIN,
  ID_LON_LOGIN_SUCESS,
  ID_LON_LOGIN_FAIL,
  ID_LON_CREATE_ACCOUNT,
  ID_LON_LOGOUT,

  //! For CStateGraveyard
  ID_LON_GY_ADD_MINION,
  ID_LON_GY_REMOVE_MINION,

  //! For CStateRoom
  ID_LON_OVERLORD_DATA,
  ID_LON_ADD_MINION,
  ID_LON_REMOVE_MINION,
  ID_LON_GAME_START,

  //! For CStateGame
  ID_LON_MINION_ATTACK,
  ID_LON_MINION_MOVE,
  ID_LON_MINION_SKILL,
  ID_LON_GAME_END
};


class CNetworkManager
{
  public:
    //! Constructor
    CNetworkManager(CGameManager *mgr, stringc ip, u16 port);

    //! Destructor
    virtual ~CNetworkManager();

    //! Host / Create a room for other user to join
    void createRoom();

    //! Join an existing room
    void joinRoom(stringc ip);

    //! Leave a game room
    void leaveRoom();

    //! Read and process incoming packets
    void readPacket();

    //! Function to send packets
    void sendPacket(BitStream* bitStream, bool toServer=true);

    //! Send chat message
    void sendChat();

    //! Read chat message packets
    void readChat(bool fromServer);

    //! Sets the default chat packet target
    //! \param toServer true to send to server. false to send to clients
    void setToServer(bool toServer);

    //! Returns a boolean to indicated if this is a room host or not
    bool IsHost();

    //! Set the port for hosting or joining game
    void setGamePort(u16 port);
  private:

    //! Pointer to the game manager
    CGameManager *mgr;

    //! Pointer to RakNet peer interface (for creating/joning room)
    RakPeerInterface *peer;

    //! Pointer to RakNet peer interface (for connecting login server)
    RakPeerInterface *client;

    //! Pointer to hold incoming packets
    Packet * packet;

    //! Is this client the room host?
    bool isHost;

    //! Is the default chat packet is send to the server?
    bool toServer;

    //! Message ID of packet (For interal purpose only)
    unsigned char msgId;

    u16 gamePort;
};

#endif // CNETWORKMANAGER_H_INCLUDED
